{% extends "base.phtml" %}

{% block content %}
<div class="box-header with-border">
    <h3 class="box-title">基本信息</h3>
</div>
<div class="box box-primary">
    <div class="box-body box-profile">
        <img class="profile-user-img img-responsive img-circle" src="{{data?data.avatar:''}}"
             alt="User profile picture">
        <h3 class="profile-username text-center">{{data?data.nickname:''}}</h3>

        <ul class="list-group list-group-unbordered">
            <li class="list-group-item">
                <b>优惠券</b> <a class="pull-right">{{data?(data.buy_num - data.card_num):''}}张</a>
            </li>
            <li class="list-group-item">
                <b>奖励天数</b> <a class="pull-right">{{data?(data.award - data.plus_num):''}}天</a>
            </li>
        </ul>

        <button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#hxModal" data-uid="{{data?data.id:''}}" >核销</button>
    </div>
</div>
<div class="box-header with-border">
    <h3 class="box-title">会员战绩</h3>
</div>
<div class="box box-primary">
    <div class="box-body box-profile">
        <ul class="list-group list-group-unbordered">
            <li class="list-group-item">
                <b>浏览量</b> <a class="pull-right">{{data?data.views:''}}次</a>
            </li>
            <li class="list-group-item">
                <b>成交量</b> <a class="pull-right">{{data?data.trade_num:''}}天</a>
            </li>
        </ul>
    </div>
</div>

<div class="box-header with-border">
    <h3 class="box-title">成交列表</h3>
</div>
<div class="box box-primary">
    <table class="table table-bordered  table-hover">
        <tr>
            <th>成交ID</th>
            <th>昵称</th>
            <th>成交数量</th>
            <th>创建时间</th>
        </tr>

        {%if count(trade_list)>0%}
        {%for k,v in trade_list%}
        <tr>
            <td>{{v.id}}</td>
            <td>{{v.nickname}}</td>
            <td>{{v.num}}</td>
            <td>{{date('Y-m-d H:i:s',v.createtime)}}</td>
        </tr>
        {%endfor%}
        {%else%}
        <tr>
            <td colspan="4">暂无成交记录</td>
        </tr>
        {%endif%}
    </table>
</div>

<div class="box-header with-border">
    <h3 class="box-title">核销记录</h3>
</div>
<div class="box box-primary">
    <table class="table table-bordered  table-hover">
        <tr>
            <th>核销ID</th>
            <th>卡券数</th>
            <th>核销天数</th>
            <th>合同号</th>
            <th>创建时间</th>
        </tr>

        {%if count(hx_list)>0%}
        {%for k,v in hx_list%}
        <tr>
            <td>{{v.id}}</td>
            <td>{{v.card_num}}</td>
            <td>{{v.day_num}}</td>
            <td>{{v.cn}}</td>
            <td>{{date('Y-m-d H:i:s',v.dateline)}}</td>
        </tr>
        {%endfor%}
        {%else%}
        <tr>
            <td colspan="4">暂无核销记录</td>
        </tr>
        {%endif%}
    </table>
</div>

<div class="modal fade" id="hxModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">核销</h4>
            </div>
            <form id='form1' data-redirect="index">
                <div class="modal-body">
                    <input type="hidden" class="form-control" name="uid">
                    <div class="form-group">
                        <label for="message-text" class="control-label">优惠券核销数量:</label>
                        <input type="text" class="form-control" name="card_num">
                    </div>
                    <div class="form-group">
                        <label for="message-text" class="control-label">奖励天数核销:</label>
                        <input type="text" class="form-control" name="day_num">
                    </div>
                    <div class="form-group">
                        <label for="message-text" class="control-label">合同编号:</label>
                        <input type="text" class="form-control" name="cn">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary " onclick="submitForm('form1', 'hexiao')">确定</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}

{% block extjs%}
<script>
    $('#hxModal').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var uid = button.data('uid');

        $("input[name='uid']").val(uid);
    });

    function submitForm(form, action) {
        form = $('#' + form);
        $.ajax({
            type: 'post',
            url: action,
            data: form.serialize(),
            success: function(data) {
                if(data.code != 200) {
                    alert(data.msg);
                }else{
                    alert('操作成功');
                    window.location.reload();
                }
            }
        });
    }

</script>
{%endblock%}